package com.atguigu.dao.Impl;

import com.atguigu.dao.StudentDao;
import com.atguigu.pojo.Student;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package com.atguigu.dao.Impl
 * @date 2024/4/22 上午10:58
 */
public class StudentDaoImpl implements StudentDao {
    private JdbcTemplate jdbcTemplate;
//注入template对象
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Student> queryAll() {

        //jdbcTemple进行数据库查询  ioc容器进行装配 不要自己实例化
        String sql="select id,name,gender,age,class as classes from students";
        List<Student> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Student>(Student.class));
        for (Student student : query) {
            System.out.println(student);

        }
        return query;
    }
}
